package com.tangcco.lockwell.service.impl;

import com.tangcco.lockwell.domain.GroupsRelationship;
import com.tangcco.lockwell.domain.User;
import com.tangcco.lockwell.repository.BaseMapper;
import com.tangcco.lockwell.repository.GroupsRelationshipMapper;
import com.tangcco.lockwell.service.GroupsRelationshipService;
import com.tangcco.lockwell.viewmodel.admin.groups.GroupsRelationshipUpdateVM;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GroupsRelationshipServiceImpl extends BaseServiceImpl<GroupsRelationship> implements GroupsRelationshipService {

    @Resource
    GroupsRelationshipMapper groupsRelationshipMapper;


    public GroupsRelationshipServiceImpl(BaseMapper<GroupsRelationship> baseMapper) {
        super(baseMapper);
    }

    // 插入一条群组用户关系记录到数据库
    @Override
    public int insert(GroupsRelationship record) {
        return groupsRelationshipMapper.insert(record);
    }
    @Override
    public int insertSelective(GroupsRelationship record) {
        return groupsRelationshipMapper.insertSelective(record);
    }
    // 动态删除群组用户关系记录的方法，可以根据id或者group_id进行删除操作
    @Override
    public int deleteGroupUserByConditionsSelective(Integer id, Integer groupId) {
        return groupsRelationshipMapper.deleteGroupUserByConditionsSelective(id, groupId);
    }
    @Override
    public int deleteByGroupId(Integer groupId) {
        return groupsRelationshipMapper.deleteByGroupId(groupId);
    }
    // 根据群组id 用户id查询信息，
    @Override
    public GroupsRelationship findGroupUsersByConditions(Integer groupId, Integer userId) {
        return groupsRelationshipMapper.findGroupUsersByConditions(groupId, userId);
    }
    //修改状态和权限
    @Override
    public int updateGroup(GroupsRelationshipUpdateVM groupsRelationshipUpdateVM) {
        return groupsRelationshipMapper.updateGroup(groupsRelationshipUpdateVM);
    }

    @Override
    public GroupsRelationship selectById(Integer id) {
        return groupsRelationshipMapper.findGroupUsersById(id);
    }
    @Override
    public List<GroupsRelationship> findByGroupIdAndUserType(Integer groupId) {
        return groupsRelationshipMapper.findByGroupIdAndUserType(groupId);
    }
    @Override
    public List<User> findGroupUsersByGroupIdAndUserType(Integer groupId) {
        return groupsRelationshipMapper.findGroupUsersByGroupIdAndUserType(groupId);
    }
}
